package com.demo.spark.rdd;

import org.apache.spark.SparkConf;
import org.apache.spark.SparkContext;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;
import java.util.List;

public class RddDistinct {
    public static void main(String[] args) {
        SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("rdd distinct");
        JavaSparkContext javasparkContext = new JavaSparkContext(sparkConf);
        javasparkContext.setLogLevel("error");
        List<Integer> data = Arrays.asList(1, 2, 4, 3, 5, 6, 7, 1, 2);
        JavaRDD<Integer> javaRDD = javasparkContext.parallelize(data);

        JavaRDD<Integer> distinctRDD1 = javaRDD.distinct();
        System.out.println(distinctRDD1.collect());
        JavaRDD<Integer> distinctRDD2 = javaRDD.distinct(2);
        System.out.println(distinctRDD2.collect());
    }
}
